********************************************************************************
*** Plot relative MSPEs of different Nowcasts
********************************************************************************
* Produces Figure 2 of Dahlhaus et al. (2025)

** PATHS (CHANGE)
global path_data "" // aggregate data (included in this package)
global path_charts "" // charts

*** Load and organize data

use "${path_data}\nowcast_mat.dta", clear

* Note: t1_model 1 - MSPE of Nowcast 2 (with Indeed data)
*       t1_model 2 - MSPE of Nowcast 1 (JVWS only)
*       t1_pvalue - DM test of MSPE 1 vs. 2
*       t2_model 1 - MSPE of Random Walk forecast
*       t2_model 2 - MSPE of Nowcast 1 (JVWS only)
*       t3_model 1 - MSPE of Random Walk forecast
*       t3_model 2 - MSPE of Nowcast 2 (with Indeed data)


* Compute MSPE ratios relative to random walk 
gen ratM1=t1_model1/t3_model1 // Nowcast 2 vs. RW
gen ratM2=t1_model2/t3_model1 // Nowcast 1 vs. RW

gen ratM1M2=ratM1/ratM2
sort ratM1M2 // sort according to percentage nowcast improvements

*** Add labels and compute graph

lab def sector 11 "Agric."
lab def sector 22 "Utilities", add
lab def sector 23 "Constr.", add
lab def sector 31 "Manuf.", add
lab def sector 41 "Wholesale", add
lab def sector 44 "Retail", add
lab def sector 48 "Transp.", add
lab def sector 51 "Infor.", add
lab def sector 52 "Finance", add
lab def sector 53 "Real est.", add
lab def sector 54 "Profess.", add
lab def sector 55 "Manag.", add
lab def sector 56 "Admin.", add
lab def sector 61 "Educ.", add
lab def sector 62 "Health", add
lab def sector 71 "Arts", add
lab def sector 72 "A&F", add
lab def sector 81 "Other s.", add
lab def sector 91 "Pub. Adm.", add
lab def sector 100 "All", add

lab val sector sector


graph bar (mean) ratM1 ratM2, ///
    over(sector, label(angle(45)) sort(ratM1M2)) ///
    ytitle("MSPE relative to Random Walk") title("") ///
    bar(1, color(blue)) bar(2, color(red)) ///
	legend(order(1 "Using JVWS and online job vacancies" 2 "Using only JVWS vacancies") pos(1) margin(0 0 0 0) region(lstyle(none))) ///
    graphregion(margin(2 2 2 2))    
	
graph export "${path_charts}\nowcast_mspe.eps", as(eps) replace